// Implementation of the ClientSocket class

#include "Master_Socket.h"
#include "../Socket/SocketException.h"


MasterSocket::MasterSocket( void )
{

}


MasterSocket::MasterSocket ( std::string host, int port )
{
  	if ( ! Socket::create() )
    {
      throw SocketException ( "Could not create client socket." );
    }

  	if ( ! Socket::connect ( host, port ) )
    {
      throw SocketException ( "Could not bind to port." );
    }
}

void MasterSocket::Initialise( std::string host, int port )
{
	if ( ! Socket::create() )
    {
      throw SocketException ( "Could not create client socket." );
    }

  	if ( ! Socket::connect ( host, port ) )
    {
      throw SocketException ( "Could not bind to port." );
    }
}


const MasterSocket& MasterSocket::operator << ( std::string& s ) const
{
  if ( ! Socket::send ( s ) )
  {
  	  
      throw SocketException ( "Could not write to socket." );
  }

  return *this;

}


const MasterSocket& MasterSocket::operator >> ( std::string& s ) const
{
  if ( ! Socket::recv ( s ) )
    {
      throw SocketException ( "Could not read from socket." );
    }

  return *this;
}
